import React, { useState } from 'react'
import PubSub from 'pubsub-js'
export default function C() {
    //初始化一个状态数据
    let [list, setList] = useState([]);
    //回调函数中有两个参数，
    //参数1：频道名称
    //参数2：该频道的值
    PubSub.subscribe('userlist', (msg, data) => {
        // console.log('频道名称:', msg)
        // console.log('频道值:', data);
        //更新状态数据
        setList(data);
    });
    PubSub.subscribe('a', (message, data1) => {
        console.log(data1);
    })
    return (
        <div style={{ width: '100%', border: '1px dashed orange' }}>
            <ul>
                {
                    list.length > 0 && list.map(item => {
                        return <li key={item.id}>
                            <span>姓名：{item.name}</span>
                            <span>年龄：{item.age}</span>
                            <span>性别：{item.sex === 'true' || item.sex === true ? '男' : '女'}</span>
                        </li>
                    })
                }
            </ul>
        </div>
    )
}
